Face Generation

In this project, you'll use generative adversarial networks to generate new images of faces.

Get the Data

You'll be using two datasets in this project:

  • MNIST
  • CelebA

Since the celebA dataset is complex and you're doing GANs in a project for the first time, we want you to test your neural network on MNIST before CelebA. Running the GANs on MNIST will allow you to see how well your model trains sooner.

If you're using FloydHub, set data_dir to "/input" and use the FloydHub data ID "R5KrjnANiKVhLWAkpXhNBe".

In [1]:
data_dir = './data'

# FloydHub - Use with data ID "R5KrjnANiKVhLWAkpXhNBe"
#data_dir = '/input'


"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
import helper

helper.download_extract('mnist', data_dir)
helper.download_extract('celeba', data_dir)
Found mnist Data
Found celeba Data

Explore the Data

MNIST

As you're aware, the MNIST dataset contains images of handwritten digits. You can view the first number of examples by changing show_n_images.

In [2]:
show_n_images = 25

"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
%matplotlib inline
import os
from glob import glob
from matplotlib import pyplot

mnist_images = helper.get_batch(glob(os.path.join(data_dir, 'mnist/*.jpg'))[:show_n_images], 28, 28, 'L')
pyplot.imshow(helper.images_square_grid(mnist_images, 'L'), cmap='gray')
Out[2]:
<matplotlib.image.AxesImage at 0x7f1de36160b8>

CelebA

The CelebFaces Attributes Dataset (CelebA) dataset contains over 200,000 celebrity images with annotations. Since you're going to be generating faces, you won't need the annotations. You can view the first number of examples by changing show_n_images.

In [3]:
show_n_images = 25

"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
mnist_images = helper.get_batch(glob(os.path.join(data_dir, 'img_align_celeba/*.jpg'))[:show_n_images], 28, 28, 'RGB')
pyplot.imshow(helper.images_square_grid(mnist_images, 'RGB'))
Out[3]:
<matplotlib.image.AxesImage at 0x7f1de35458d0>

Preprocess the Data

Since the project's main focus is on building the GANs, we'll preprocess the data for you. The values of the MNIST and CelebA dataset will be in the range of -0.5 to 0.5 of 28x28 dimensional images. The CelebA images will be cropped to remove parts of the image that don't include a face, then resized down to 28x28.

The MNIST images are black and white images with a single color channel while the CelebA images have 3 color channels (RGB color channel).

Build the Neural Network

You'll build the components necessary to build a GANs by implementing the following functions below:

  • model_inputs
  • discriminator
  • generator
  • model_loss
  • model_opt
  • train

Check the Version of TensorFlow and Access to GPU

This will check to make sure you have the correct version of TensorFlow and access to a GPU

In [4]:
"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
from distutils.version import LooseVersion
import warnings
import tensorflow as tf

# Check TensorFlow Version
assert LooseVersion(tf.__version__) >= LooseVersion('1.0'), 'Please use TensorFlow version 1.0 or newer.  You are using {}'.format(tf.__version__)
print('TensorFlow Version: {}'.format(tf.__version__))

# Check for a GPU
if not tf.test.gpu_device_name():
    warnings.warn('No GPU found. Please use a GPU to train your neural network.')
else:
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
TensorFlow Version: 1.0.0
Default GPU Device: /gpu:0

Input

Implement the model_inputs function to create TF Placeholders for the Neural Network. It should create the following placeholders:

  • Real input images placeholder with rank 4 using image_width, image_height, and image_channels.
  • Z input placeholder with rank 2 using z_dim.
  • Learning rate placeholder with rank 0.

Return the placeholders in the following the tuple (tensor of real input images, tensor of z data)

In [5]:
import problem_unittests as tests

def model_inputs(image_width, image_height, image_channels, z_dim):
    """
    Create the model inputs
    :param image_width: The input image width
    :param image_height: The input image height
    :param image_channels: The number of image channels
    :param z_dim: The dimension of Z
    :return: Tuple of (tensor of real input images, tensor of z data, learning rate)
    """
    # TODO: Implement Function
    
    real_inputs_ph = tf.placeholder(tf.float32,
                                 shape=(None, image_width, image_height, image_channels),
                                 name='real_inputs_ph')
    
    
    z_inputs_ph = tf.placeholder(tf.float32,
                                 (None, z_dim),
                                 name='z_inputs_ph')
    
    learning_rate_ph = tf.placeholder(tf.float32,
                                   name='learning_rate_ph')

    return real_inputs_ph, z_inputs_ph, learning_rate_ph


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_model_inputs(model_inputs)
Tests Passed

Discriminator

Implement discriminator to create a discriminator neural network that discriminates on images. This function should be able to reuse the variables in the neural network. Use tf.variable_scope with a scope name of "discriminator" to allow the variables to be reused. The function should return a tuple of (tensor output of the discriminator, tensor logits of the discriminator).

In [6]:
def discriminator(images, reuse=False):
    """
    Create the discriminator network
    :param images: Tensor of input image(s)
    :param reuse: Boolean if the weights should be reused
    :return: Tuple of (tensor output of the discriminator, tensor logits of the discriminator)
    """
    # TODO: Implement Function

    _discriminator_alpha = 0.2
    _conv_init_size = 64
    _2_times_conv_init_size = 2*_conv_init_size
    _4_times_conv_init_size = 4*_conv_init_size
    _8_times_conv_init_size = 8*_conv_init_size

    
    with tf.variable_scope('discriminator', reuse=reuse):
        
        ########################### 1st ############################
        _1st_conv = tf.layers.conv2d(images/255, 
                                     _conv_init_size, 
                                     5, 2, 'SAME')
        _1st_leaky_relu = tf.maximum(_discriminator_alpha * _1st_conv, 
                                     _1st_conv)
        
        
        ########################### 2nd ############################
        _2nd_conv = tf.layers.conv2d(_1st_leaky_relu, 
                                     _2_times_conv_init_size,
                                     5, 2, 'SAME')
        _2nd_batch_norm = tf.layers.batch_normalization(_2nd_conv, 
                                                        training=True)
        _2nd_leaky_relu = tf.maximum(_discriminator_alpha * _2nd_batch_norm,
                                     _2nd_batch_norm)
        
        
        
        ########################### 3rd ############################
        _3rd_conv = tf.layers.conv2d(_2nd_leaky_relu, 
                                     _4_times_conv_init_size, 
                                     5, 1, 'SAME')
        _3rd_batch_norm = tf.layers.batch_normalization(_3rd_conv, 
                                                        training=True)
        _3rd_leaky_relu = tf.maximum(_discriminator_alpha * _3rd_batch_norm, 
                                     _3rd_batch_norm)
        
        
        
        ########################### 4th ############################
        _4th_conv = tf.layers.conv2d(_3rd_leaky_relu, 
                                     _8_times_conv_init_size, 
                                     5, 1, 'SAME')
        _4th_batch_norm = tf.layers.batch_normalization(_4th_conv, 
                                                        training=True)
        _4th_leaky_relu = tf.maximum(_discriminator_alpha * _4th_batch_norm,
                                     _4th_batch_norm)
        
        
        ########################### flatten ############################
        _flat_4th_leaky_relu = tf.reshape(_4th_leaky_relu, (-1, 7*7*_8_times_conv_init_size))
        
        ########################## fully connected dense ###############
        _discriminator_logits = tf.layers.dense(_flat_4th_leaky_relu, 1)
        
        ########################## segmoid logits ###############
        _discriminator_output = tf.sigmoid(_discriminator_logits)
        
        return _discriminator_output, _discriminator_logits


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_discriminator(discriminator, tf)
Tests Passed

Generator

Implement generator to generate an image using z. This function should be able to reuse the variables in the neural network. Use tf.variable_scope with a scope name of "generator" to allow the variables to be reused. The function should return the generated 28 x 28 x out_channel_dim images.

In [7]:
def generator(z, out_channel_dim, is_train=True):
    """
    Create the generator network
    :param z: Input z
    :param out_channel_dim: The number of channels in the output image
    :param is_train: Boolean if generator is being used for training
    :return: The tensor output of the generator
    """
    # TODO: Implement Function
    
    _generator_alpha = 0.2
    
    _conv_init_size = 64
    _2_times_conv_init_size = 2*_conv_init_size
    _4_times_conv_init_size = 4*_conv_init_size
    _8_times_conv_init_size = 8*_conv_init_size
    
    with tf.variable_scope('generator', reuse= not is_train):
        
        ########################### 1st ############################
        _1st_dense = tf.layers.dense(z,
                                     7*7*_8_times_conv_init_size)
        _1st_dense_flatten = tf.reshape(_1st_dense,
                                        (-1, 7, 7, _8_times_conv_init_size))
        _1st_out = tf.maximum(_generator_alpha*_1st_dense_flatten,
                              _1st_dense_flatten)
        
        
        ########################### 2nd ############################
        _2nd_conv = tf.layers.conv2d_transpose(_1st_out, 
                                             _4_times_conv_init_size,
                                             3, 1, 'SAME')
        _2nd_batch_norm = tf.layers.batch_normalization(_2nd_conv, 
                                                        training=is_train)
        _2nd_leaky_relu = tf.maximum(_generator_alpha * _2nd_batch_norm, 
                                     _2nd_batch_norm)
        
        ########################### 3rd ############################
        _3rd_conv = tf.layers.conv2d_transpose(_2nd_leaky_relu, 
                                             _2_times_conv_init_size, 
                                             3, 1, 'SAME')
        _3rd_batch_norm = tf.layers.batch_normalization(_3rd_conv,
                                                    training=is_train)
        _3rd_leaky_relu = tf.maximum(_generator_alpha * _3rd_batch_norm, 
                                     _3rd_batch_norm)
        
        ########################### 4th ############################
        _4th_conv = tf.layers.conv2d_transpose(_3rd_leaky_relu,
                                               _conv_init_size,
                                               3, 2, 'SAME')
        _4th_batch_norm = tf.layers.batch_normalization(_4th_conv,
                                                    training=is_train)
        _4th_leaky_relu = tf.maximum(_generator_alpha * _4th_batch_norm,
                            _4th_batch_norm)
        
        ########################## logits ##########################
        _generator_logits = tf.layers.conv2d_transpose(_4th_leaky_relu,
                                            out_channel_dim,
                                            3, 2, 'SAME')
        
        ################### hyperbolic tangent logits ###############
        _generator_output = tf.tanh(_generator_logits)
        
        return _generator_output


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_generator(generator, tf)
Tests Passed

Loss

Implement model_loss to build the GANs for training and calculate the loss. The function should return a tuple of (discriminator loss, generator loss). Use the following functions you implemented:

  • discriminator(images, reuse=False)
  • generator(z, out_channel_dim, is_train=True)
In [8]:
def model_loss(input_real, input_z, out_channel_dim):
    """
    Get the loss for the discriminator and generator
    :param input_real: Images from the real dataset
    :param input_z: Z input
    :param out_channel_dim: The number of channels in the output image
    :return: A tuple of (discriminator loss, generator loss)
    """
    # TODO: Implement Function
    
    _generator_model = generator(input_z, out_channel_dim)
    _discriminator_real_model, _discriminator_real_logits = discriminator(input_real)
    _discriminator_fake_model, _discriminator_fake_logits = discriminator(_generator_model, reuse=True)
    
    _discriminator_real_loss = tf.reduce_mean(
        tf.nn.sigmoid_cross_entropy_with_logits(
            logits=_discriminator_real_logits, 
            labels=tf.ones_like(_discriminator_real_model) * 0.9))
    
    _discriminator_fake_loss = tf.reduce_mean(
        tf.nn.sigmoid_cross_entropy_with_logits(
            logits=_discriminator_fake_logits,
            labels=tf.zeros_like(_discriminator_fake_model)))
    
    _total_discriminator_loss = _discriminator_real_loss + _discriminator_fake_loss

    _total_generator_loss = tf.reduce_mean(
        tf.nn.sigmoid_cross_entropy_with_logits(
            logits=_discriminator_fake_logits,
            labels=tf.ones_like(_discriminator_fake_model)))
    
    return _total_discriminator_loss, _total_generator_loss


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_model_loss(model_loss)
Tests Passed

Optimization

Implement model_opt to create the optimization operations for the GANs. Use tf.trainable_variables to get all the trainable variables. Filter the variables with names that are in the discriminator and generator scope names. The function should return a tuple of (discriminator training operation, generator training operation).

In [9]:
def model_opt(d_loss, g_loss, learning_rate, beta1):
    """
    Get optimization operations
    :param d_loss: Discriminator loss Tensor
    :param g_loss: Generator loss Tensor
    :param learning_rate: Learning Rate Placeholder
    :param beta1: The exponential decay rate for the 1st moment in the optimizer
    :return: A tuple of (discriminator training operation, generator training operation)
    """
    # TODO: Implement Function
    
    _model_variables = tf.trainable_variables()
    _discriminator_variables = [variable for variable in _model_variables if variable.name.startswith('discriminator')]
    _generator_variables = [variable for variable in _model_variables if variable.name.startswith('generator')]

    ########################## optimizers ###############
    _discriminator_opt = tf.train.AdamOptimizer(learning_rate, beta1=beta1).minimize(d_loss, var_list=_discriminator_variables)
    _generator_opt = tf.train.AdamOptimizer(learning_rate, beta1=beta1).minimize(g_loss, var_list=_generator_variables)

    return _discriminator_opt, _generator_opt


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_model_opt(model_opt, tf)
Tests Passed

Neural Network Training

Show Output

Use this function to show the current output of the generator during training. It will help you determine how well the GANs is training.

In [10]:
"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
import numpy as np

def show_generator_output(sess, n_images, input_z, out_channel_dim, image_mode):
    """
    Show example output for the generator
    :param sess: TensorFlow session
    :param n_images: Number of Images to display
    :param input_z: Input Z Tensor
    :param out_channel_dim: The number of channels in the output image
    :param image_mode: The mode to use for images ("RGB" or "L")
    """
    cmap = None if image_mode == 'RGB' else 'gray'
    z_dim = input_z.get_shape().as_list()[-1]
    example_z = np.random.uniform(-1, 1, size=[n_images, z_dim])

    samples = sess.run(
        generator(input_z, out_channel_dim, False),
        feed_dict={input_z: example_z})

    images_grid = helper.images_square_grid(samples, image_mode)
    pyplot.imshow(images_grid, cmap=cmap)
    pyplot.show()

Train

Implement train to build and train the GANs. Use the following functions you implemented:

  • model_inputs(image_width, image_height, image_channels, z_dim)
  • model_loss(input_real, input_z, out_channel_dim)
  • model_opt(d_loss, g_loss, learning_rate, beta1)

Use the show_generator_output to show generator output while you train. Running show_generator_output for every batch will drastically increase training time and increase the size of the notebook. It's recommended to print the generator output every 100 batches.

In [11]:
def train(epoch_count, batch_size, z_dim, learning_rate, beta1, get_batches, data_shape, data_image_mode):
    """
    Train the GAN
    :param epoch_count: Number of epochs
    :param batch_size: Batch Size
    :param z_dim: Z dimension
    :param learning_rate: Learning Rate
    :param beta1: The exponential decay rate for the 1st moment in the optimizer
    :param get_batches: Function to get batches
    :param data_shape: Shape of the data
    :param data_image_mode: The image mode to use for images ("RGB" or "L")
    """
    # TODO: Build Model
    
    tf.reset_default_graph()
    
    _real_input, _z_input, _ = model_inputs(data_shape[1], data_shape[2], data_shape[3], z_dim)
    
    _discriminator_loss, _generator_loss = model_loss(_real_input, _z_input, data_shape[3])
    
    _discriminator_opt, _generator_opt = model_opt(_discriminator_loss, _generator_loss, learning_rate, beta1)
    
    steps = 0
    
    
    with tf.Session() as train_session:
        train_session.run(tf.global_variables_initializer())
        for epoch in range(epoch_count):
            for batch_images in get_batches(batch_size):
                # TODO: Train Model
                batch_images *= 2
                steps += 1
            
                batch_z = np.random.uniform(-1, 1, size=(batch_size, z_dim))
                
                train_session.run(_discriminator_opt, feed_dict={_real_input: batch_images, _z_input: batch_z})
                train_session.run(_generator_opt, feed_dict={_z_input: batch_z})
                
                if steps % 100 == 0:
                    discriminator_loss = _discriminator_loss.eval({_z_input: batch_z, _real_input: batch_images})
                    generator_loss = _generator_loss.eval({_z_input: batch_z})

                    print("Epoch {}/{}...".format(steps, epoch_count))
                    print("==============Losses================")
                    print("Discriminator: {:.4f}".format(discriminator_loss))
                    print("Generator: {:.4f}".format(generator_loss))
                    
                    show_generator_output(train_session, show_n_images, _z_input, data_shape[3], data_image_mode)
                
                

MNIST

Test your GANs architecture on MNIST. After 2 epochs, the GANs should be able to generate images that look like handwritten digits. Make sure the loss of the generator is lower than the loss of the discriminator or close to 0.

In [12]:
batch_size = 32
z_dim = 128
learning_rate = 0.0002
beta1 = 0.4


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
epochs = 2

mnist_dataset = helper.Dataset('mnist', glob(os.path.join(data_dir, 'mnist/*.jpg')))
with tf.Graph().as_default():
    train(epochs, batch_size, z_dim, learning_rate, beta1, mnist_dataset.get_batches,
          mnist_dataset.shape, mnist_dataset.image_mode)
Epoch 100/2...
==============Losses================
Discriminator: 0.5344
Generator: 2.2693
Epoch 200/2...
==============Losses================
Discriminator: 0.9506
Generator: 1.2918
Epoch 300/2...
==============Losses================
Discriminator: 0.6061
Generator: 1.7423
Epoch 400/2...
==============Losses================
Discriminator: 1.3668
Generator: 0.6388
Epoch 500/2...
==============Losses================
Discriminator: 1.4444
Generator: 0.5129
Epoch 600/2...
==============Losses================
Discriminator: 0.7275
Generator: 1.3983
Epoch 700/2...
==============Losses================
Discriminator: 1.4996
Generator: 0.4813
Epoch 800/2...
==============Losses================
Discriminator: 1.3896
Generator: 0.6726
Epoch 900/2...
==============Losses================
Discriminator: 1.4997
Generator: 0.5410
Epoch 1000/2...
==============Losses================
Discriminator: 2.2625
Generator: 3.6750
Epoch 1100/2...
==============Losses================
Discriminator: 0.9236
Generator: 2.2193
Epoch 1200/2...
==============Losses================
Discriminator: 1.2699
Generator: 0.6783
Epoch 1300/2...
==============Losses================
Discriminator: 1.1940
Generator: 0.8022
Epoch 1400/2...
==============Losses================
Discriminator: 1.0407
Generator: 0.9136
Epoch 1500/2...
==============Losses================
Discriminator: 1.1546
Generator: 0.8414
Epoch 1600/2...
==============Losses================
Discriminator: 0.8981
Generator: 1.3294
Epoch 1700/2...
==============Losses================
Discriminator: 0.8794
Generator: 1.4375
Epoch 1800/2...
==============Losses================
Discriminator: 1.1474
Generator: 0.7364
Epoch 1900/2...
==============Losses================
Discriminator: 1.1975
Generator: 1.1086
Epoch 2000/2...
==============Losses================
Discriminator: 1.1854
Generator: 0.7856
Epoch 2100/2...
==============Losses================
Discriminator: 2.5351
Generator: 0.1988
Epoch 2200/2...
==============Losses================
Discriminator: 0.8999
Generator: 1.7044
Epoch 2300/2...
==============Losses================
Discriminator: 2.1327
Generator: 0.3202
Epoch 2400/2...
==============Losses================
Discriminator: 0.9412
Generator: 1.0661
Epoch 2500/2...
==============Losses================
Discriminator: 1.8865
Generator: 0.3492
Epoch 2600/2...
==============Losses================
Discriminator: 0.6902
Generator: 1.8233
Epoch 2700/2...
==============Losses================
Discriminator: 1.0482
Generator: 0.9397
Epoch 2800/2...
==============Losses================
Discriminator: 1.6974
Generator: 0.3973
Epoch 2900/2...
==============Losses================
Discriminator: 1.1011
Generator: 0.9599
Epoch 3000/2...
==============Losses================
Discriminator: 1.1891
Generator: 0.8994
Epoch 3100/2...
==============Losses================
Discriminator: 0.9154
Generator: 1.7724
Epoch 3200/2...
==============Losses================
Discriminator: 1.1656
Generator: 0.9864
Epoch 3300/2...
==============Losses================
Discriminator: 0.9722
Generator: 1.0292
Epoch 3400/2...
==============Losses================
Discriminator: 1.7006
Generator: 0.4645
Epoch 3500/2...
==============Losses================
Discriminator: 0.8919
Generator: 1.1022
Epoch 3600/2...
==============Losses================
Discriminator: 0.8586
Generator: 1.2060
Epoch 3700/2...
==============Losses================
Discriminator: 1.1009
Generator: 0.8849
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-12-4d16a3dd59ca> in <module>()
     13 with tf.Graph().as_default():
     14     train(epochs, batch_size, z_dim, learning_rate, beta1, mnist_dataset.get_batches,
---> 15           mnist_dataset.shape, mnist_dataset.image_mode)

/usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
     64         if type is None:
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:
     68                 return

/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in get_controller(self, default)
   3682     finally:
   3683       if self._enforce_nesting:
-> 3684         if self.stack[-1] is not default:
   3685           raise AssertionError(
   3686               "Nesting violated for default stack of %s objects"

IndexError: list index out of range

CelebA

Run your GANs on CelebA. It will take around 20 minutes on the average GPU to run one epoch. You can run the whole epoch or stop when it starts to generate realistic faces.

In [13]:
"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
epochs = 1

celeba_dataset = helper.Dataset('celeba', glob(os.path.join(data_dir, 'img_align_celeba/*.jpg')))
with tf.Graph().as_default():
    train(epochs, batch_size, z_dim, learning_rate, beta1, celeba_dataset.get_batches,
          celeba_dataset.shape, celeba_dataset.image_mode)
Epoch 100/1...
==============Losses================
Discriminator: 3.3410
Generator: 0.0683
Epoch 200/1...
==============Losses================
Discriminator: 1.3908
Generator: 0.7423
Epoch 300/1...
==============Losses================
Discriminator: 1.6699
Generator: 1.2462
Epoch 400/1...
==============Losses================
Discriminator: 1.3855
Generator: 0.5265
Epoch 500/1...
==============Losses================
Discriminator: 1.5920
Generator: 0.4882
Epoch 600/1...
==============Losses================
Discriminator: 1.4860
Generator: 0.4432
Epoch 700/1...
==============Losses================
Discriminator: 1.7254
Generator: 2.5117
Epoch 800/1...
==============Losses================
Discriminator: 1.4855
Generator: 0.5637
Epoch 900/1...
==============Losses================
Discriminator: 1.3142
Generator: 0.6023
Epoch 1000/1...
==============Losses================
Discriminator: 1.7416
Generator: 0.3944
Epoch 1100/1...
==============Losses================
Discriminator: 1.3753
Generator: 0.6557
Epoch 1200/1...
==============Losses================
Discriminator: 1.1828
Generator: 0.7202
Epoch 1300/1...
==============Losses================
Discriminator: 1.6395
Generator: 0.3674
Epoch 1400/1...
==============Losses================
Discriminator: 1.4922
Generator: 0.5414
Epoch 1500/1...
==============Losses================
Discriminator: 1.0598
Generator: 0.9936
Epoch 1600/1...
==============Losses================
Discriminator: 1.2996
Generator: 0.6322
Epoch 1700/1...
==============Losses================
Discriminator: 1.8591
Generator: 0.3235
Epoch 1800/1...
==============Losses================
Discriminator: 1.2163
Generator: 0.6609
Epoch 1900/1...
==============Losses================
Discriminator: 1.1177
Generator: 0.8179
Epoch 2000/1...
==============Losses================
Discriminator: 1.1649
Generator: 1.0851
Epoch 2100/1...
==============Losses================
Discriminator: 1.2013
Generator: 0.7194
Epoch 2200/1...
==============Losses================
Discriminator: 1.6756
Generator: 0.4528
Epoch 2300/1...
==============Losses================
Discriminator: 1.0577
Generator: 1.9292
Epoch 2400/1...
==============Losses================
Discriminator: 1.3508
Generator: 1.4017
Epoch 2500/1...
==============Losses================
Discriminator: 1.0462
Generator: 0.8712
Epoch 2600/1...
==============Losses================
Discriminator: 1.4615
Generator: 0.9052
Epoch 2700/1...
==============Losses================
Discriminator: 1.2984
Generator: 0.9290
Epoch 2800/1...
==============Losses================
Discriminator: 0.9298
Generator: 1.3437
Epoch 2900/1...
==============Losses================
Discriminator: 1.3537
Generator: 0.7133
Epoch 3000/1...
==============Losses================
Discriminator: 1.0929
Generator: 1.0280
Epoch 3100/1...
==============Losses================
Discriminator: 1.4918
Generator: 0.4168
Epoch 3200/1...
==============Losses================
Discriminator: 1.8080
Generator: 0.2906
Epoch 3300/1...
==============Losses================
Discriminator: 1.5888
Generator: 0.3882
Epoch 3400/1...
==============Losses================
Discriminator: 1.1810
Generator: 0.6781
Epoch 3500/1...
==============Losses================
Discriminator: 2.0275
Generator: 0.2563
Epoch 3600/1...
==============Losses================
Discriminator: 1.5681
Generator: 0.4168
Epoch 3700/1...
==============Losses================
Discriminator: 1.2333
Generator: 0.6804
Epoch 3800/1...
==============Losses================
Discriminator: 1.5156
Generator: 0.5437
Epoch 3900/1...
==============Losses================
Discriminator: 0.9537
Generator: 0.9264
Epoch 4000/1...
==============Losses================
Discriminator: 1.0461
Generator: 0.9288
Epoch 4100/1...
==============Losses================
Discriminator: 1.3631
Generator: 0.5566
Epoch 4200/1...
==============Losses================
Discriminator: 1.3883
Generator: 0.4901
Epoch 4300/1...
==============Losses================
Discriminator: 1.8089
Generator: 0.3075
Epoch 4400/1...
==============Losses================
Discriminator: 1.3346
Generator: 0.5604
Epoch 4500/1...
==============Losses================
Discriminator: 1.0525
Generator: 2.1496
Epoch 4600/1...
==============Losses================
Discriminator: 1.5798
Generator: 1.1427
Epoch 4700/1...
==============Losses================
Discriminator: 1.3371
Generator: 0.7537
Epoch 4800/1...
==============Losses================
Discriminator: 1.0490
Generator: 1.0668
Epoch 4900/1...
==============Losses================
Discriminator: 1.3429
Generator: 0.5198
Epoch 5000/1...
==============Losses================
Discriminator: 1.0701
Generator: 0.8994
Epoch 5100/1...
==============Losses================
Discriminator: 1.8094
Generator: 0.3178
Epoch 5200/1...
==============Losses================
Discriminator: 1.0075
Generator: 0.8797
Epoch 5300/1...
==============Losses================
Discriminator: 1.1411
Generator: 1.7912
Epoch 5400/1...
==============Losses================
Discriminator: 1.1067
Generator: 0.6965
Epoch 5500/1...
==============Losses================
Discriminator: 1.1463
Generator: 0.9889
Epoch 5600/1...
==============Losses================
Discriminator: 1.1539
Generator: 0.7120
Epoch 5700/1...
==============Losses================
Discriminator: 1.1812
Generator: 0.6514
Epoch 5800/1...
==============Losses================
Discriminator: 1.6546
Generator: 0.3695
Epoch 5900/1...
==============Losses================
Discriminator: 1.1033
Generator: 1.0243
Epoch 6000/1...
==============Losses================
Discriminator: 0.9439
Generator: 1.2121
Epoch 6100/1...
==============Losses================
Discriminator: 0.8538
Generator: 1.2296
Epoch 6200/1...
==============Losses================
Discriminator: 0.9591
Generator: 0.9318
Epoch 6300/1...
==============Losses================
Discriminator: 0.9904
Generator: 1.7525
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-13-94d2c67c310b> in <module>()
      7 with tf.Graph().as_default():
      8     train(epochs, batch_size, z_dim, learning_rate, beta1, celeba_dataset.get_batches,
----> 9           celeba_dataset.shape, celeba_dataset.image_mode)

/usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
     64         if type is None:
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:
     68                 return

/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in get_controller(self, default)
   3682     finally:
   3683       if self._enforce_nesting:
-> 3684         if self.stack[-1] is not default:
   3685           raise AssertionError(
   3686               "Nesting violated for default stack of %s objects"

IndexError: list index out of range

Submitting This Project

When submitting this project, make sure to run all the cells before saving the notebook. Save the notebook file as "dlnd_face_generation.ipynb" and save it as a HTML file under "File" -> "Download as". Include the "helper.py" and "problem_unittests.py" files in your submission.